<template>
  <div>
    <!-- 返利冻结明细查询 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @resetChange="resetChange" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        columnsRef="qjhBankInfoMaintain"
        :isSelectColumn="false"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :onColumnsChange="columns => (this.columns = columns)"
      >
        <template slot="controls" slot-scope="props">

          <multiuse-button size="small" type="primary" :click="exportHandler">导 出</multiuse-button>

        </template>
      </FilterTable>
    </Spin>
    <BaseDialog :visible.sync="isDealer" title="经销商查询" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SearchDealer :rowData="formData" @close="emitCloseHandler1" />
    </BaseDialog>
  </div>
</template>
<script>
import { dealerMixin } from '@/pages/repair/batchEventManagement/dealerMixin';
import { dictionary } from '@/utils/dictMixin';
import { queryList, exportExcel, getFundsType ,exporturl} from '@/api/omFinance/MoneyManage/RebateFreezingDetailsQuery';
import { exportExcelFile } from '@/utils/index';
import SearchDealer from '../ownerSeacher';
export default {
  name: 'BankInfoMaintain',
  mixins: [dictionary, dealerMixin],

  data() {
    this.BaseTable = null;


    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {},
      formData: {},
      exportLoading: false,
      visible: false,
      isDealer: false
    };
  },
  components: {
   SearchDealer
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    //获取经销商名称
    this.getAllDelears(this.columns, ['dealerName'], 'table');

  },
  created() {
      this.getFundsType();

  },
  methods: {
     // 账户资金类型
    async getFundsType(powerType) {
      const res = (await getFundsType({ powerType: powerType, fundsType: 1 })).data.map(x => ({ text: x.accountTypeName, value: x.id }));
      this.topFilterList.find(x => x.fieldName == 'accountTypeId').itemList = res;
    },
    seacherFun() {
      this.isDealer = true;
    },

    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    resetChange(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    emitCloseHandler1(val, data) {
      this.isDealer = val;
      let dealerCodes = [];
      let dealerNames = [];
      if (data) {
        data.map(x => {
          dealerCodes.push(x.dealerCode);
          dealerNames.push(x.dealerName);
        });
        this.dealerCode = dealerCodes.toString();
        this.topFilterList.find(x => x.fieldName == 'dealerCode').initialValue = dealerCodes.toString();
      }
    },
    // 导出
    async exportHandler() {
        let json = Object.assign({}, { CODE: 'CODE_00000243' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
      // await this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
      //   confirmButtonText: '下载',
      //   cancelButtonText: '取消',
      //   type: 'warning'
      // })
      //   .then(() => {
      //     this.exportLoading = true;

      //     exportExcel(this.fetchParams)
      //       .then(response => {
      //         exportExcelFile(response.data, '返利冻结明细');
      //         this.exportLoading = false;
      //       })
      //       .catch(err => {
      //         console.log(err);
      //       });
      //   })
      //   .catch(() => {
      //     this.$message({
      //       type: 'info',
      //       message: '已取消'
      //     });
      //   });
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          }
        },

        {
          type: 'RANGE_DATE',
          label: '冻结日期范围',
          fieldName: 'beginCreditExpireDate|endCreditExpireDate',
          dateType: 'exactdaterange',
          placeholder: '请选择',
          initialValue: []
        },
      {
          type: 'SELECT',
          label: '返利账户类型',
          fieldName: 'accountTypeId',
          placeholder: '请选择',
          itemList: []
        },
        {
          type: 'RANGE_INPUT_NUMBER',
          label: '冻结金额',
          placeholder: '请输入',
          fieldName: 'beginfrostAmount|endfrostAmount',

        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },

        {
          title: '经销商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          dictItems:[],
          filterType: 'input'
        },
        {
          title: '冻结人',
          dataIndex: 'createdName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '冻结金额',
          dataIndex: 'frostAmount',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '冻结前金额',
          dataIndex: 'beforeAvailableAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          numberFormat: true
        },
        {
          title: '冻结后金额',
          dataIndex: 'afterAvailableAmount',
          sorter: true,
          filter: true,
          filterType: 'input',
           numberFormat: true

        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
